Use macros DEG() and RAD(), defined in grtcirc.h, for conversions between degrees...
authoroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 5 May 2006 20:36:41 +0000 (20:36 +0000)
committeroliskoli <oliskoli@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 5 May 2006 20:36:41 +0000 (20:36 +0000)
12 files changed:
gpsbabel/arcdist.c
gpsbabel/copilot.c
gpsbabel/coto.c
gpsbabel/csv_util.c
gpsbabel/grtcirc.c
gpsbabel/grtcirc.h
gpsbabel/interpolate.c
gpsbabel/overlay.c
gpsbabel/position.c
gpsbabel/psp.c
gpsbabel/saroute.c
gpsbabel/vitosmt.c

index 52a34fb0cdf33ca3c19398332d8cfba348422f63..cbb8ced956e1a8f446120fd5605f4db8cb0b5fac 100644 (file)
@@ -99,9 +99,9 @@ arcdist_process(void)
                }
                if ( ed->distance == BADVAL || ed->distance >= pos_dist ) {
                   if ( ptsopt ) {
-                     dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0
-                                  waypointp->latitude*M_PI/180.0
-                                  waypointp->longitude*M_PI/180.0 );
+                     dist = gcdist( RAD(lat2), RAD(lon2)
+                                  RAD(waypointp->latitude)
+                                  RAD(waypointp->longitude) );
                   }
                   else {
                      dist = linedist(lat1, lon1, lat2, lon2, 
index c2828fdadf4ea80cdc79dc6b9415083103780f58..879d49a9b59cfe9adb5f267fd619b840448b4fb0 100644 (file)
@@ -22,8 +22,7 @@
 #include "defs.h"
 #include "coldsync/palm.h"
 #include "coldsync/pdb.h"
-
-static double conv = 180.0 / M_PI;
+#include "grtcirc.h"
 
 #define MYNAME         "CoPilot Waypoint"
 #define MYTYPE                 0x77617970      /* wayp */
@@ -92,9 +91,9 @@ data_read(void)
 
                rec = (struct record *) pdb_rec->data;
                wpt_tmp->longitude =
-                 -pdb_read_double(&rec->longitude) * conv;
+                 DEG(-pdb_read_double(&rec->longitude));
                wpt_tmp->latitude =
-                 pdb_read_double(&rec->latitude) * conv;
+                 DEG(pdb_read_double(&rec->latitude));
                wpt_tmp->altitude =
                  pdb_read_double(&rec->elevation) * .3048;
 
@@ -124,9 +123,8 @@ copilot_writewpt(const waypoint *wpt)
 
        rec = xcalloc(sizeof(*rec)+1141,1);
 
-       pdb_write_double(&rec->latitude, wpt->latitude / conv);
-       pdb_write_double(&rec->longitude,
-               -wpt->longitude / conv);
+       pdb_write_double(&rec->latitude, RAD(wpt->latitude));
+       pdb_write_double(&rec->longitude, RAD(-wpt->longitude));
        pdb_write_double(&rec->elevation,
                wpt->altitude / .3048);
        pdb_write_double(&rec->magvar, 0);
index 3b537d06a03881bd6576dc1b869f6a890542aca3..38e5e3ff15d66150384e50ffc5f8056a6187b7f7 100644 (file)
@@ -28,6 +28,7 @@
 #include "csv_util.h"
 #include "coldsync/palm.h"
 #include "coldsync/pdb.h"
+#include "grtcirc.h"
 
 #define MYNAME "cotoGPS"
 
@@ -194,8 +195,8 @@ coto_track_read(struct pdb *pdb)
 
                rec = (struct record_track *) pdb_rec->data;
                
-               wpt_tmp->longitude = -pdb_read_double(&rec->longitude)*360.0/(2.0*M_PI); 
-               wpt_tmp->latitude = pdb_read_double(&rec->latitude)*360.0/(2.0*M_PI);
+               wpt_tmp->longitude = DEG(-pdb_read_double(&rec->longitude));
+               wpt_tmp->latitude = DEG(pdb_read_double(&rec->latitude));
 
                // It's not the course, so leave it out for now
                // wpt_tmp->course = pdb_read_double(&rec->arc);
@@ -261,8 +262,8 @@ coto_wpt_read(struct pdb *pdb)
 
                rec = (struct record_wpt *) pdb_rec->data;
                        
-               wpt_tmp->longitude = -pdb_read_double(&rec->lon)*360.0/(2.0*M_PI); 
-               wpt_tmp->latitude = pdb_read_double(&rec->lat)*360.0/(2.0*M_PI);
+               wpt_tmp->longitude = DEG(-pdb_read_double(&rec->lon));
+               wpt_tmp->latitude = DEG(pdb_read_double(&rec->lat));
                
                wpt_tmp->shortname = xstrndup(rec->name, sizeof(rec->name));
                
@@ -379,8 +380,8 @@ coto_wpt_write(const waypoint *wpt)
                size += strlen(notes);
        rec = xcalloc(size, 1);
        
-       pdb_write_double(&rec->lon, -2.0*M_PI*wpt->longitude/360.0);
-       pdb_write_double(&rec->lat, 2.0*M_PI*wpt->latitude/360.0);
+       pdb_write_double(&rec->lon, RAD(-wpt->longitude));
+       pdb_write_double(&rec->lat, RAD(wpt->latitude));
        strncpy(rec->name, shortname, MAX_MARKER_NAME_LENGTH);
        
        if (notes)
index be00ddb5680c509a7d9ac0cd61e9d6cf245d5c34..b1d172e5f0c2f59a4899e62fc30b96a80f8dbbf6 100644 (file)
@@ -1083,8 +1083,8 @@ xcsv_waypt_pr(const waypoint *wpt)
     queue *elem, *tmp;
     
     if ( oldlon < 900 ) {
-       pathdist += radtomiles(gcdist(oldlat*M_PI/180,oldlon*M_PI/180,
-                       wpt->latitude*M_PI/180,wpt->longitude*M_PI/180));
+       pathdist += radtomiles(gcdist(RAD(oldlat),RAD(oldlon),
+                       RAD(wpt->latitude),RAD(wpt->longitude)));
     }
     oldlon = wpt->longitude;
     oldlat = wpt->latitude;
index 2bb40b0b2151ab42f33cf95fe6559a8d3cc6a815..eb72780ed1d59af3ba37959c8708c631ffd395b2 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include "defs.h"
+#include "grtcirc.h"
 
 static const double EARTH_RAD = 6378137.0;
 
@@ -120,9 +121,9 @@ double linedist(double lat1, double lon1,
   int newpoints;
   
   /* degrees to radians */
-  lat1 *= M_PI/180.0;  lon1 *= M_PI/180.0;
-  lat2 *= M_PI/180.0;  lon2 *= M_PI/180.0;
-  lat3 *= M_PI/180.0;  lon3 *= M_PI/180.0;
+  lat1 = RAD(lat1);  lon1 = RAD(lon1);
+  lat2 = RAD(lat2);  lon2 = RAD(lon2);
+  lat3 = RAD(lat3);  lon3 = RAD(lon3);
 
   newpoints = 1;
   if ( lat1 == _lat1 && lat2 == _lat2 && lon1 == _lon1 && lon2 == _lon2) {
@@ -266,8 +267,8 @@ void linepart(double lat1, double lon1,
   double sinphi = 0;
   
   /* degrees to radians */
-  lat1 *= M_PI/180.0;  lon1 *= M_PI/180.0;
-  lat2 *= M_PI/180.0;  lon2 *= M_PI/180.0;
+  lat1 = RAD(lat1);  lon1 = RAD(lon1);
+  lat2 = RAD(lat2);  lon2 = RAD(lon2);
 
   /* polar to ECEF rectangular */
   x1 = cos(lon1)*cos(lat1); y1 = sin(lat1); z1 = sin(lon1)*cos(lat1);
@@ -313,12 +314,12 @@ void linepart(double lat1, double lon1,
     if ( zr > 1 ) zr = 1;
     if ( zr < -1 ) zr = -1;
     
-    *reslat = asin(yr) * 180 / M_PI;   
+    *reslat = DEG(asin(yr));
     if( xr == 0 && zr == 0 ) {
       *reslon = 0;
     }
     else {
-      *reslon = atan2( zr, xr ) * 180 / M_PI;
+      *reslon = DEG(atan2( zr, xr ));
     } 
   }
 }
index 1fb749e40d434e0a14f0d272f07912e05e7e128c..c50ee4591169373ca8ab560bb54996658800d990 100644 (file)
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
 
  */
+#ifndef GRTCIRC_H
+#define GRTCIRC_H
+
 double gcdist( double lat1, double lon1, double lat2, double lon2 );
 double heading( double lat1, double lon1, double lat2, double lon2 );
 
@@ -36,3 +40,5 @@ void linepart(double lat1, double lon1,
 
 #define DEG(x) ((x)*180.0/M_PI)
 #define RAD(x) ((x)*M_PI/180.0)
+
+#endif
index f054ae4a47f1dad03fbda96bb572b15b5d222d71..189750d3c7765b74f1292b9bd13629aee8271d80 100644 (file)
@@ -96,10 +96,10 @@ interpfilt_process(void)
                            }
                        }
                        else if ( opt_dist ) {
-                           rt1 = lat1 * M_PI / 180;
-                           rn1 = lon1 * M_PI / 180;
-                           rt2 = wpt->latitude * M_PI / 180;
-                           rn2 = wpt->longitude * M_PI / 180;
+                           rt1 = RAD(lat1);
+                           rn1 = RAD(lon1);
+                           rt2 = RAD(wpt->latitude);
+                           rn2 = RAD(wpt->longitude);
                            curdist = gcdist( rt1, rn1, rt2, rn2 );
                            curdist = radtomiles(curdist);
                            if ( curdist > dist ) {     
index 785919ae499488fddebc8510382693451968b54e..fdf3a0f687ac37f19d430bc29dc778fd83f1693f 100644 (file)
@@ -580,8 +580,8 @@ static void symbol_deinit(const route_head *hd)
   QUEUE_FOR_EACH(&(hd->waypoint_list), elem, tmp)
   {
     waypointp = (waypoint *) elem;
-    lat2 = waypointp->latitude *M_PI/180.0 ;
-    lon2 = waypointp->longitude*M_PI/180.0 ;
+    lat2 = RAD(waypointp->latitude);
+    lon2 = RAD(waypointp->longitude);
     if (i)
     {
       d   = gcdist(lat1, lon1, lat2, lon2 );
@@ -604,8 +604,8 @@ static void symbol_deinit(const route_head *hd)
   while (elem!=&(hd->waypoint_list) && dd<dist/2.0)
   {
     waypointp = (waypoint *) elem;
-    lat2 = waypointp->latitude *M_PI/180.0;
-    lon2 = waypointp->longitude*M_PI/180.0;
+    lat2 = RAD(waypointp->latitude);
+    lon2 = RAD(waypointp->longitude);
     if (i)
     {
       d   = gcdist(lat1, lon1, lat2, lon2 );
@@ -621,7 +621,7 @@ static void symbol_deinit(const route_head *hd)
 //  d = acos( sin(lats)*sin(late)+cos(lats)*cos(late)*cos(lone-lons) );
   dd = acos( (sin(late) - sin(lats)*cos(d))/(cos(lats)*sin(d)) );
   if (lone<lons) dd = -dd;   // correction because the ambiguity of acos function
-  dd = dd * 180.0/M_PI;      // azimuth
+  dd = DEG(dd);              // azimuth
   dd = 360.0 - (dd + 270.0); // make it anticlockwise and start counting on x-axis
   dd = dd <   0.0 ? dd + 360.0 : dd; // normalizing
   dd = dd > 360.0 ? dd - 360.0 : dd; // normalizing
@@ -629,7 +629,7 @@ static void symbol_deinit(const route_head *hd)
   /* name of route */
   /* plot text at the last point of route */
   govl_dir = dd;  // approximated text rotation, correct value must be the azimuth in UTM
-  symbol_text(lon1*180.0/M_PI,lat1*180.0/M_PI,hd->rte_name,govl_group_cnt);
+  symbol_text(DEG(lon1),DEG(lat1),hd->rte_name,govl_group_cnt);
   govl_dir = 0.0; // restore
 }
 
index 87daf7e0c30663bb182a191d5ae04a7052d1b30e..25f6f7d414e37442b915d559cef636110790a661 100644 (file)
@@ -78,10 +78,10 @@ static double
 gc_distance(double lat1, double lon1, double lat2, double lon2)
 {
        return gcdist( 
-           (lat1 * M_PI) / 180.0,
-           (lon1 * M_PI) / 180.0,
-           (lat2 * M_PI) / 180.0,
-           (lon2 * M_PI) / 180.0
+           RAD(lat1),
+           RAD(lon1),
+           RAD(lat2),
+           RAD(lon2)
            );
 }
 
index 29973af1a61399e70b205642ea548e1c66dc2207..1208530785720dbb79ffd0253ed3723ab7038d99 100644 (file)
@@ -23,6 +23,7 @@
 #include "defs.h"
 #include "cet_util.h"
 #include <ctype.h>
+#include "grtcirc.h"
 
 #define MYNAME "PSP"
 
@@ -238,11 +239,11 @@ psp_read(void)
 
             /* 8 bytes - latitude in radians */
            radians = psp_fread_double(psp_file_in);
-            lat = (radians * 180.0) / M_PI;
+            lat = DEG(radians);
 
             /* 8 bytes - longitude in radians */
            radians = psp_fread_double(psp_file_in);
-            lon = (radians * 180.0) / M_PI;
+            lon = DEG(radians);
 
             /* since we don't know the origin of this PSP file, we use  */
             /* the grid byte adjust longitude, if necessary, mimicing   */
@@ -356,8 +357,8 @@ psp_waypt_pr(const waypoint *wpt)
         }
 
         /* convert lat/long back to radians */
-       lat = (wpt->latitude * M_PI) / 180.0;
-        lon = (wpt->longitude * M_PI) / 180.0;
+       lat = RAD(wpt->latitude);
+        lon = RAD(wpt->longitude);
         
        pindex++;
        le_write16(tbuf, pindex);
index 196565f252bc6a21287845efc8947eabb97679f0..a93056ad3027c155e1837cec5873406bed808c84 100644 (file)
@@ -367,9 +367,9 @@ my_read(void)
                                if ( times ) {
                                        if ( !first ) {
                                           double dist = radtomiles(gcdist( 
-                                               lat*M_PI/180, -lon*M_PI/180
-                                               oldlat*M_PI/180
-                                               -oldlon*M_PI/180 ));    
+                                               RAD(lat), RAD(-lon)
+                                               RAD(oldlat)
+                                               RAD(-oldlon) ));        
                                           totaldist += dist;
                                           if ( totaldist > seglen ) {
                                                   totaldist = seglen;
index 22c7d96597694263920086c1b8af10b5b1ada3b1..3ca048651ba3eadf31efa00ceaa078861aedcfc4 100644 (file)
@@ -26,6 +26,7 @@
 
 #define MYNAME "vitosmt"
 #include "defs.h"
+#include "grtcirc.h"
 
 static FILE                            *infile =0;
 static FILE                            *ofs    =0;
@@ -175,8 +176,8 @@ vitosmt_read(void)
 
                wpt_tmp = waypt_new();
                
-               wpt_tmp->latitude       =(latrad * 180) / M_PI;
-               wpt_tmp->longitude      =(lonrad * 180) / M_PI;
+               wpt_tmp->latitude       =DEG(latrad);
+               wpt_tmp->longitude      =DEG(lonrad);
                wpt_tmp->altitude       =elev;
 
                tmStruct.tm_year        =timestamp[0]+100;
@@ -270,9 +271,9 @@ vitosmt_waypt_pr(const waypoint *waypointp)
        ++count;
        workbuffer = xcalloc(vitosmt_datasize,1);
 
-       WriteDouble(&workbuffer[position], (M_PI*waypointp->latitude)/180 ); 
+       WriteDouble(&workbuffer[position], RAD(waypointp->latitude) ); 
        position += sizeof(double);
-       WriteDouble(&workbuffer[position], (M_PI*waypointp->longitude)/180 );
+       WriteDouble(&workbuffer[position], RAD(waypointp->longitude) );
        position += sizeof(double);
        if ( waypointp->altitude-1 > unknown_alt)
                WriteDouble(&workbuffer[position], waypointp->altitude );